/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-11     AisinoChip   first version
 */

#include "board.h"
#include <stdlib.h>
#include "drv_pin_table.h"

#define     PIN_FUNC_MAX_SIZE   10

typedef struct
{
    char    name[5];
    uint8_t func[PIN_FUNC_MAX_SIZE];
} pin_item_t;

#ifdef SOC_PACKAGE_QFN32
static const pin_item_t gpio_table[] =
{
#ifdef BSP_USING_GPIO1
    { "PA0", { AF_GPIO, AF_SPI2_SCK, AF_UART2_CTS, AF_TIM2_CH1_ETR, AF_UART4_TX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    { "PA1", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RTS, AF_TIM2_CH2, AF_UART4_RX, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA2", { AF_GPIO, AF_SPI1_MOSI, AF_UART2_TX, AF_TIM2_CH3, AF_SPI1_CS, AF_TIM15_CH1, AF_LPUART1_TX, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA3", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RX, AF_TIM2_CH4, AF_SPI2_MISO, AF_TIM15_CH2, AF_LPUART1_RX, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PA4", { AF_GPIO, AF_SPI1_CS, AF_SPI3_CS, AF_INVALID, AF_SPI2_MOSI, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_I2S1_WS, AF_TIM3_CH2 } },
    { "PA5", { AF_GPIO, AF_SPI1_SCK, AF_INVALID, AF_TIM2_CH1_ETR, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA6", { AF_GPIO, AF_SPI1_MISO, AF_TIM3_CH1, AF_TIM1_BKIN, AF_SPI1_IO3, AF_INVALID, AF_TIM16_CH1, AF_COMP1_OUT, AF_I2S1_MCK, AF_INVALID } },
    { "PA7", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM1_CH1N, AF_SPI1_IO2, AF_TIM14_CH1, AF_TIM17_CH1, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA8", { AF_GPIO, AF_MCO, AF_INVALID, AF_TIM1_CH1, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM4_ETR } },
    { "PA9", { AF_GPIO, AF_MCO, AF_UART1_TX, AF_TIM1_CH2, AF_SPI2_MOSI, AF_TIM15_BKIN, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_TIM2_CH3 } },
    {"PA10", { AF_GPIO, AF_INVALID, AF_UART1_RX, AF_TIM1_CH3, AF_SPI2_MISO, AF_TIM17_BKIN, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM2_CH4 } },
    {"PA11", { AF_GPIO, AF_SPI1_MISO, AF_UART1_CTS, AF_TIM1_CH4, AF_UART3_TX, AF_CAN1_RX, AF_TIM1_CH1N, AF_COMP1_OUT, AF_I2S1_MCK, AF_TIM4_CH1 } },
    {"PA12", { AF_GPIO, AF_SPI1_MOSI, AF_UART1_RTS, AF_TIM1_ETR, AF_UART3_RX, AF_CAN1_TX, AF_TIM1_CH2N, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM4_CH2 } },
    {"PA13", { AF_GPIO, AF_SWDIO, AF_IR_OUT, AF_INVALID, AF_UART3_CTS, AF_I2C1_SCL, AF_TIM16_CH1N, AF_INVALID, AF_INVALID, AF_TIM4_CH3 } },
    {"PA14", { AF_GPIO, AF_SWCLK, AF_UART2_TX, AF_INVALID, AF_INVALID, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_BKIN } },
    {"PA15", { AF_GPIO, AF_TDI, AF_UART2_RX, AF_TIM2_CH1_ETR, AF_UART4_RTS, AF_SPI3_CS, AF_SPI1_CS, AF_I2C1_SCL, AF_I2S1_WS, AF_TIM1_BKIN } },
    { "PB0", { AF_GPIO, AF_SPI1_CS, AF_TIM3_CH3, AF_TIM1_CH2N, AF_UART3_RX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_I2S1_WS, AF_INVALID } },
    { "PB1", { AF_GPIO, AF_TIM14_CH1, AF_TIM3_CH4, AF_TIM1_CH3N, AF_MCO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB3", { AF_GPIO, AF_TDO, AF_TIM1_CH2, AF_TIM2_CH2, AF_SPI3_SCK, AF_SPI1_SCK, AF_UART2_TX, AF_TIM3_ETR, AF_I2S1_CK, AF_TIM4_ETR } },
    { "PB4", { AF_GPIO, AF_TRST, AF_TIM3_CH1, AF_TIM17_BKIN, AF_SPI3_MISO, AF_SPI1_MISO, AF_UART2_RX, AF_INVALID, AF_I2S1_MCK, AF_TIM16_CH1 } },
    { "PB5", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM16_BKIN, AF_SPI3_MOSI, AF_CAN2_RX, AF_INVALID, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM17_CH1 } },
    { "PB6", { AF_GPIO, AF_UART1_TX, AF_TIM1_CH3, AF_TIM16_CH1N, AF_SPI2_MISO, AF_CAN2_TX, AF_I2C1_SCL, AF_INVALID, AF_INVALID, AF_TIM4_CH1 } },
    { "PB7", { AF_GPIO, AF_UART1_RX, AF_TIM3_CH4, AF_TIM17_CH1N, AF_SPI2_MOSI, AF_UART4_CTS, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_TIM4_CH2 } },
#endif
    { "PF0", { AF_GPIO, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF1", { AF_GPIO, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_SPI2_SCK, AF_INVALID, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF3", { AF_GPIO, AF_BOOT, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
};
#elif defined(SOC_PACKAGE_LQFP48)
static const pin_item_t gpio_table[] =
{
#ifdef BSP_USING_GPIO1
    { "PA0", { AF_GPIO, AF_SPI2_SCK, AF_UART2_CTS, AF_TIM2_CH1_ETR, AF_UART4_TX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    { "PA1", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RTS, AF_TIM2_CH2, AF_UART4_RX, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA2", { AF_GPIO, AF_SPI1_MOSI, AF_UART2_TX, AF_TIM2_CH3, AF_SPI1_CS, AF_TIM15_CH1, AF_LPUART1_TX, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA3", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RX, AF_TIM2_CH4, AF_SPI2_MISO, AF_TIM15_CH2, AF_LPUART1_RX, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PA4", { AF_GPIO, AF_SPI1_CS, AF_SPI3_CS, AF_INVALID, AF_SPI2_MOSI, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_I2S1_WS, AF_TIM3_CH2 } },
    { "PA5", { AF_GPIO, AF_SPI1_SCK, AF_INVALID, AF_TIM2_CH1_ETR, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA6", { AF_GPIO, AF_SPI1_MISO, AF_TIM3_CH1, AF_TIM1_BKIN, AF_SPI1_IO3, AF_INVALID, AF_TIM16_CH1, AF_COMP1_OUT, AF_I2S1_MCK, AF_INVALID } },
    { "PA7", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM1_CH1N, AF_SPI1_IO2, AF_TIM14_CH1, AF_TIM17_CH1, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA8", { AF_GPIO, AF_MCO, AF_INVALID, AF_TIM1_CH1, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM4_ETR } },
    { "PA9", { AF_GPIO, AF_MCO, AF_UART1_TX, AF_TIM1_CH2, AF_SPI2_MOSI, AF_TIM15_BKIN, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_TIM2_CH3 } },
    {"PA10", { AF_GPIO, AF_INVALID, AF_UART1_RX, AF_TIM1_CH3, AF_SPI2_MISO, AF_TIM17_BKIN, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM2_CH4 } },
    {"PA11", { AF_GPIO, AF_SPI1_MISO, AF_UART1_CTS, AF_TIM1_CH4, AF_UART3_TX, AF_CAN1_RX, AF_TIM1_CH1N, AF_COMP1_OUT, AF_I2S1_MCK, AF_TIM4_CH1 } },
    {"PA12", { AF_GPIO, AF_SPI1_MOSI, AF_UART1_RTS, AF_TIM1_ETR, AF_UART3_RX, AF_CAN1_TX, AF_TIM1_CH2N, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM4_CH2 } },
    {"PA13", { AF_GPIO, AF_SWDIO, AF_IR_OUT, AF_INVALID, AF_UART3_CTS, AF_I2C1_SCL, AF_TIM16_CH1N, AF_INVALID, AF_INVALID, AF_TIM4_CH3 } },
    {"PA14", { AF_GPIO, AF_SWCLK, AF_UART2_TX, AF_INVALID, AF_INVALID, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_BKIN } },
    {"PA15", { AF_GPIO, AF_TDI, AF_UART2_RX, AF_TIM2_CH1_ETR, AF_UART4_RTS, AF_SPI3_CS, AF_SPI1_CS, AF_I2C1_SCL, AF_I2S1_WS, AF_TIM1_BKIN } },
    { "PB0", { AF_GPIO, AF_SPI1_CS, AF_TIM3_CH3, AF_TIM1_CH2N, AF_UART3_RX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_I2S1_WS, AF_INVALID } },
    { "PB1", { AF_GPIO, AF_TIM14_CH1, AF_TIM3_CH4, AF_TIM1_CH3N, AF_MCO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB2", { AF_GPIO, AF_SPI2_MISO, AF_INVALID, AF_INVALID, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB3", { AF_GPIO, AF_TDO, AF_TIM1_CH2, AF_TIM2_CH2, AF_SPI3_SCK, AF_SPI1_SCK, AF_UART2_TX, AF_TIM3_ETR, AF_I2S1_CK, AF_TIM4_ETR } },
    { "PB4", { AF_GPIO, AF_TRST, AF_TIM3_CH1, AF_TIM17_BKIN, AF_SPI3_MISO, AF_SPI1_MISO, AF_UART2_RX, AF_INVALID, AF_I2S1_MCK, AF_TIM16_CH1 } },
    { "PB5", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM16_BKIN, AF_SPI3_MOSI, AF_CAN2_RX, AF_INVALID, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM17_CH1 } },
    { "PB6", { AF_GPIO, AF_UART1_TX, AF_TIM1_CH3, AF_TIM16_CH1N, AF_SPI2_MISO, AF_CAN2_TX, AF_I2C1_SCL, AF_INVALID, AF_INVALID, AF_TIM4_CH1 } },
    { "PB7", { AF_GPIO, AF_UART1_RX, AF_TIM3_CH4, AF_TIM17_CH1N, AF_SPI2_MOSI, AF_UART4_CTS, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_TIM4_CH2 } },
    { "PB8", { AF_GPIO, AF_TIM1_BKIN, AF_TIM15_BKIN, AF_TIM16_CH1, AF_SPI2_SCK, AF_UART3_TX, AF_I2C1_SCL, AF_CAN1_RX, AF_COMP1_OUT, AF_TIM4_CH3 } },
    { "PB9", { AF_GPIO, AF_IR_OUT, AF_INVALID, AF_TIM17_CH1, AF_SPI2_CS, AF_UART3_RX, AF_I2C1_SDA, AF_CAN1_TX, AF_COMP2_OUT, AF_INVALID } },
    {"PB10", { AF_GPIO, AF_LPUART1_RX, AF_UART3_TX, AF_TIM2_CH3, AF_SPI2_SCK, AF_SPI1_SCK, AF_I2C2_SCL, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    {"PB11", { AF_GPIO, AF_LPUART1_TX, AF_UART3_RX, AF_TIM2_CH4, AF_SPI2_MOSI, AF_SPI1_CS, AF_I2C2_SDA, AF_COMP2_OUT, AF_INVALID, AF_INVALID } },
    {"PB12", { AF_GPIO, AF_INVALID, AF_INVALID, AF_TIM1_BKIN, AF_SPI2_CS, AF_TIM15_BKIN, AF_INVALID, AF_CAN2_RX, AF_INVALID, AF_INVALID } },
    {"PB13", { AF_GPIO, AF_UART3_CTS, AF_INVALID, AF_TIM1_CH1N, AF_SPI2_SCK, AF_TIM15_CH1N, AF_I2C2_SCL, AF_CAN2_TX, AF_INVALID, AF_INVALID } },
    {"PB14", { AF_GPIO, AF_UART3_RTS, AF_MCO2, AF_TIM1_CH2N, AF_SPI2_MISO, AF_TIM15_CH1, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PB15", { AF_GPIO, AF_INVALID, AF_TIM15_CH1N, AF_TIM1_CH3N, AF_SPI2_MOSI, AF_TIM15_CH2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
#endif
#ifdef BSP_USING_GPIO2
    {"PC13", { AF_GPIO, AF_INVALID, AF_TIM1_BKIN, AF_INVALID, AF_INVALID, AF_TIM1_CH1N, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC14", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC15", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
#endif
    { "PF0", { AF_GPIO, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF1", { AF_GPIO, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_SPI2_SCK, AF_INVALID, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF3", { AF_GPIO, AF_BOOT, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
};
#elif defined (SOC_PACKAGE_LQFP64)
static const pin_item_t gpio_table[] =
{
#ifdef BSP_USING_GPIO1
    { "PA0", { AF_GPIO, AF_SPI2_SCK, AF_UART2_CTS, AF_TIM2_CH1_ETR, AF_UART4_TX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    { "PA1", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RTS, AF_TIM2_CH2, AF_UART4_RX, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA2", { AF_GPIO, AF_SPI1_MOSI, AF_UART2_TX, AF_TIM2_CH3, AF_SPI1_CS, AF_TIM15_CH1, AF_LPUART1_TX, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA3", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RX, AF_TIM2_CH4, AF_SPI2_MISO, AF_TIM15_CH2, AF_LPUART1_RX, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PA4", { AF_GPIO, AF_SPI1_CS, AF_SPI3_CS, AF_INVALID, AF_SPI2_MOSI, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_I2S1_WS, AF_TIM3_CH2 } },
    { "PA5", { AF_GPIO, AF_SPI1_SCK, AF_INVALID, AF_TIM2_CH1_ETR, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA6", { AF_GPIO, AF_SPI1_MISO, AF_TIM3_CH1, AF_TIM1_BKIN, AF_SPI1_IO3, AF_INVALID, AF_TIM16_CH1, AF_COMP1_OUT, AF_I2S1_MCK, AF_INVALID } },
    { "PA7", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM1_CH1N, AF_SPI1_IO2, AF_TIM14_CH1, AF_TIM17_CH1, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA8", { AF_GPIO, AF_MCO, AF_INVALID, AF_TIM1_CH1, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM4_ETR } },
    { "PA9", { AF_GPIO, AF_MCO, AF_UART1_TX, AF_TIM1_CH2, AF_SPI2_MOSI, AF_TIM15_BKIN, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_TIM2_CH3 } },
    {"PA10", { AF_GPIO, AF_INVALID, AF_UART1_RX, AF_TIM1_CH3, AF_SPI2_MISO, AF_TIM17_BKIN, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM2_CH4 } },
    {"PA11", { AF_GPIO, AF_SPI1_MISO, AF_UART1_CTS, AF_TIM1_CH4, AF_UART3_TX, AF_CAN1_RX, AF_TIM1_CH1N, AF_COMP1_OUT, AF_I2S1_MCK, AF_TIM4_CH1 } },
    {"PA12", { AF_GPIO, AF_SPI1_MOSI, AF_UART1_RTS, AF_TIM1_ETR, AF_UART3_RX, AF_CAN1_TX, AF_TIM1_CH2N, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM4_CH2 } },
    {"PA13", { AF_GPIO, AF_SWDIO, AF_IR_OUT, AF_INVALID, AF_UART3_CTS, AF_I2C1_SCL, AF_TIM16_CH1N, AF_INVALID, AF_INVALID, AF_TIM4_CH3 } },
    {"PA14", { AF_GPIO, AF_SWCLK, AF_UART2_TX, AF_INVALID, AF_INVALID, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_BKIN } },
    {"PA15", { AF_GPIO, AF_TDI, AF_UART2_RX, AF_TIM2_CH1_ETR, AF_UART4_RTS, AF_SPI3_CS, AF_SPI1_CS, AF_I2C1_SCL, AF_I2S1_WS, AF_TIM1_BKIN } },
    { "PB0", { AF_GPIO, AF_SPI1_CS, AF_TIM3_CH3, AF_TIM1_CH2N, AF_UART3_RX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_I2S1_WS, AF_INVALID } },
    { "PB1", { AF_GPIO, AF_TIM14_CH1, AF_TIM3_CH4, AF_TIM1_CH3N, AF_MCO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB2", { AF_GPIO, AF_SPI2_MISO, AF_INVALID, AF_INVALID, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB3", { AF_GPIO, AF_TDO, AF_TIM1_CH2, AF_TIM2_CH2, AF_SPI3_SCK, AF_SPI1_SCK, AF_UART2_TX, AF_TIM3_ETR, AF_I2S1_CK, AF_TIM4_ETR } },
    { "PB4", { AF_GPIO, AF_TRST, AF_TIM3_CH1, AF_TIM17_BKIN, AF_SPI3_MISO, AF_SPI1_MISO, AF_UART2_RX, AF_INVALID, AF_I2S1_MCK, AF_TIM16_CH1 } },
    { "PB5", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM16_BKIN, AF_SPI3_MOSI, AF_CAN2_RX, AF_INVALID, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM17_CH1 } },
    { "PB6", { AF_GPIO, AF_UART1_TX, AF_TIM1_CH3, AF_TIM16_CH1N, AF_SPI2_MISO, AF_CAN2_TX, AF_I2C1_SCL, AF_INVALID, AF_INVALID, AF_TIM4_CH1 } },
    { "PB7", { AF_GPIO, AF_UART1_RX, AF_TIM3_CH4, AF_TIM17_CH1N, AF_SPI2_MOSI, AF_UART4_CTS, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_TIM4_CH2 } },
    { "PB8", { AF_GPIO, AF_TIM1_BKIN, AF_TIM15_BKIN, AF_TIM16_CH1, AF_SPI2_SCK, AF_UART3_TX, AF_I2C1_SCL, AF_CAN1_RX, AF_COMP1_OUT, AF_TIM4_CH3 } },
    { "PB9", { AF_GPIO, AF_IR_OUT, AF_INVALID, AF_TIM17_CH1, AF_SPI2_CS, AF_UART3_RX, AF_I2C1_SDA, AF_CAN1_TX, AF_COMP2_OUT, AF_INVALID } },
    {"PB10", { AF_GPIO, AF_LPUART1_RX, AF_UART3_TX, AF_TIM2_CH3, AF_SPI2_SCK, AF_SPI1_SCK, AF_I2C2_SCL, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    {"PB11", { AF_GPIO, AF_LPUART1_TX, AF_UART3_RX, AF_TIM2_CH4, AF_SPI2_MOSI, AF_SPI1_CS, AF_I2C2_SDA, AF_COMP2_OUT, AF_INVALID, AF_INVALID } },
    {"PB12", { AF_GPIO, AF_INVALID, AF_INVALID, AF_TIM1_BKIN, AF_SPI2_CS, AF_TIM15_BKIN, AF_INVALID, AF_CAN2_RX, AF_INVALID, AF_INVALID } },
    {"PB13", { AF_GPIO, AF_UART3_CTS, AF_INVALID, AF_TIM1_CH1N, AF_SPI2_SCK, AF_TIM15_CH1N, AF_I2C2_SCL, AF_CAN2_TX, AF_INVALID, AF_INVALID } },
    {"PB14", { AF_GPIO, AF_UART3_RTS, AF_MCO2, AF_TIM1_CH2N, AF_SPI2_MISO, AF_TIM15_CH1, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PB15", { AF_GPIO, AF_INVALID, AF_TIM15_CH1N, AF_TIM1_CH3N, AF_SPI2_MOSI, AF_TIM15_CH2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
#endif
#ifdef BSP_USING_GPIO2
    { "PC0", { AF_GPIO, AF_LPUART1_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_CH1, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PC1", { AF_GPIO, AF_LPUART1_TX, AF_TIM15_CH1, AF_INVALID, AF_INVALID, AF_TIM1_CH2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PC2", { AF_GPIO, AF_SPI2_MISO, AF_TIM15_CH2, AF_INVALID, AF_INVALID, AF_TIM1_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PC3", { AF_GPIO, AF_SPI2_MOSI, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_CH4, AF_INVALID, AF_SPI4_CS, AF_INVALID, AF_INVALID } },
    { "PC4", { AF_GPIO, AF_UART1_TX, AF_INVALID, AF_TIM2_CH1_ETR, AF_UART3_TX, AF_TIM1_ETR, AF_I2C2_SCL, AF_SPI4_MISO, AF_INVALID, AF_INVALID } },
    { "PC5", { AF_GPIO, AF_UART1_RX, AF_INVALID, AF_TIM2_CH2, AF_UART3_RX, AF_TIM15_BKIN, AF_INVALID, AF_SPI4_MOSI, AF_INVALID, AF_INVALID } },
    { "PC6", { AF_GPIO, AF_TIM3_CH1, AF_SPI2_IO3, AF_TIM2_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI4_IO3, AF_INVALID, AF_INVALID } },
    { "PC7", { AF_GPIO, AF_TIM3_CH2, AF_SPI2_IO2, AF_TIM2_CH4, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI4_IO2, AF_INVALID, AF_INVALID } },
    { "PC8", { AF_GPIO, AF_TIM3_CH3, AF_TIM1_CH1, AF_SPI3_IO3, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI4_SCK, AF_INVALID, AF_INVALID } },
    { "PC9", { AF_GPIO, AF_TIM3_CH4, AF_TIM1_CH2, AF_SPI3_IO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC10", { AF_GPIO, AF_INVALID, AF_TIM1_CH3, AF_SPI3_SCK, AF_UART3_TX, AF_UART4_TX, AF_INVALID, AF_SPI3_IO3, AF_INVALID, AF_INVALID } },
    {"PC11", { AF_GPIO, AF_INVALID, AF_TIM1_CH4, AF_SPI3_MISO, AF_UART3_RX, AF_UART4_RX, AF_INVALID, AF_SPI3_SCK, AF_INVALID, AF_INVALID } },
    {"PC12", { AF_GPIO, AF_INVALID, AF_TIM14_CH1, AF_SPI3_MOSI, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC13", { AF_GPIO, AF_INVALID, AF_TIM1_BKIN, AF_INVALID, AF_INVALID, AF_TIM1_CH1N, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC14", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC15", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD2", { AF_GPIO, AF_MCO2, AF_TIM3_ETR, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
#endif
    { "PF0", { AF_GPIO, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF1", { AF_GPIO, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_SPI2_SCK, AF_INVALID, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF3", { AF_GPIO, AF_BOOT, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
};
#elif defined SOC_PACKAGE_LQFP100
static const pin_item_t gpio_table[] =
{
#ifdef BSP_USING_GPIO1
    { "PA0", { AF_GPIO, AF_SPI2_SCK, AF_UART2_CTS, AF_TIM2_CH1_ETR, AF_UART4_TX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    { "PA1", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RTS, AF_TIM2_CH2, AF_UART4_RX, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA2", { AF_GPIO, AF_SPI1_MOSI, AF_UART2_TX, AF_TIM2_CH3, AF_SPI1_CS, AF_TIM15_CH1, AF_LPUART1_TX, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA3", { AF_GPIO, AF_SPI1_SCK, AF_UART2_RX, AF_TIM2_CH4, AF_SPI2_MISO, AF_TIM15_CH2, AF_LPUART1_RX, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PA4", { AF_GPIO, AF_SPI1_CS, AF_SPI3_CS, AF_INVALID, AF_SPI2_MOSI, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_I2S1_WS, AF_TIM3_CH2 } },
    { "PA5", { AF_GPIO, AF_SPI1_SCK, AF_INVALID, AF_TIM2_CH1_ETR, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_I2S1_CK, AF_INVALID } },
    { "PA6", { AF_GPIO, AF_SPI1_MISO, AF_TIM3_CH1, AF_TIM1_BKIN, AF_SPI1_IO3, AF_INVALID, AF_TIM16_CH1, AF_COMP1_OUT, AF_I2S1_MCK, AF_INVALID } },
    { "PA7", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM1_CH1N, AF_SPI1_IO2, AF_TIM14_CH1, AF_TIM17_CH1, AF_COMP2_OUT, AF_I2S1_SD, AF_INVALID } },
    { "PA8", { AF_GPIO, AF_MCO, AF_INVALID, AF_TIM1_CH1, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM4_ETR } },
    { "PA9", { AF_GPIO, AF_MCO, AF_UART1_TX, AF_TIM1_CH2, AF_SPI2_MOSI, AF_TIM15_BKIN, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_TIM2_CH3 } },
    {"PA10", { AF_GPIO, AF_INVALID, AF_UART1_RX, AF_TIM1_CH3, AF_SPI2_MISO, AF_TIM17_BKIN, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_TIM2_CH4 } },
    {"PA11", { AF_GPIO, AF_SPI1_MISO, AF_UART1_CTS, AF_TIM1_CH4, AF_UART3_TX, AF_CAN1_RX, AF_TIM1_CH1N, AF_COMP1_OUT, AF_I2S1_MCK, AF_TIM4_CH1 } },
    {"PA12", { AF_GPIO, AF_SPI1_MOSI, AF_UART1_RTS, AF_TIM1_ETR, AF_UART3_RX, AF_CAN1_TX, AF_TIM1_CH2N, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM4_CH2 } },
    {"PA13", { AF_GPIO, AF_SWDIO, AF_IR_OUT, AF_INVALID, AF_UART3_CTS, AF_I2C1_SCL, AF_TIM16_CH1N, AF_INVALID, AF_INVALID, AF_TIM4_CH3 } },
    {"PA14", { AF_GPIO, AF_SWCLK, AF_UART2_TX, AF_INVALID, AF_INVALID, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_BKIN } },
    {"PA15", { AF_GPIO, AF_TDI, AF_UART2_RX, AF_TIM2_CH1_ETR, AF_UART4_RTS, AF_SPI3_CS, AF_SPI1_CS, AF_I2C1_SCL, AF_I2S1_WS, AF_TIM1_BKIN } },
    { "PB0", { AF_GPIO, AF_SPI1_CS, AF_TIM3_CH3, AF_TIM1_CH2N, AF_UART3_RX, AF_INVALID, AF_INVALID, AF_COMP1_OUT, AF_I2S1_WS, AF_INVALID } },
    { "PB1", { AF_GPIO, AF_TIM14_CH1, AF_TIM3_CH4, AF_TIM1_CH3N, AF_MCO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB2", { AF_GPIO, AF_SPI2_MISO, AF_INVALID, AF_INVALID, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PB3", { AF_GPIO, AF_TDO, AF_TIM1_CH2, AF_TIM2_CH2, AF_SPI3_SCK, AF_SPI1_SCK, AF_UART2_TX, AF_TIM3_ETR, AF_I2S1_CK, AF_TIM4_ETR } },
    { "PB4", { AF_GPIO, AF_TRST, AF_TIM3_CH1, AF_TIM17_BKIN, AF_SPI3_MISO, AF_SPI1_MISO, AF_UART2_RX, AF_INVALID, AF_I2S1_MCK, AF_TIM16_CH1 } },
    { "PB5", { AF_GPIO, AF_SPI1_MOSI, AF_TIM3_CH2, AF_TIM16_BKIN, AF_SPI3_MOSI, AF_CAN2_RX, AF_INVALID, AF_COMP2_OUT, AF_I2S1_SD, AF_TIM17_CH1 } },
    { "PB6", { AF_GPIO, AF_UART1_TX, AF_TIM1_CH3, AF_TIM16_CH1N, AF_SPI2_MISO, AF_CAN2_TX, AF_I2C1_SCL, AF_INVALID, AF_INVALID, AF_TIM4_CH1 } },
    { "PB7", { AF_GPIO, AF_UART1_RX, AF_TIM3_CH4, AF_TIM17_CH1N, AF_SPI2_MOSI, AF_UART4_CTS, AF_I2C1_SDA, AF_INVALID, AF_INVALID, AF_TIM4_CH2 } },
    { "PB8", { AF_GPIO, AF_TIM1_BKIN, AF_TIM15_BKIN, AF_TIM16_CH1, AF_SPI2_SCK, AF_UART3_TX, AF_I2C1_SCL, AF_CAN1_RX, AF_COMP1_OUT, AF_TIM4_CH3 } },
    { "PB9", { AF_GPIO, AF_IR_OUT, AF_INVALID, AF_TIM17_CH1, AF_SPI2_CS, AF_UART3_RX, AF_I2C1_SDA, AF_CAN1_TX, AF_COMP2_OUT, AF_INVALID } },
    {"PB10", { AF_GPIO, AF_LPUART1_RX, AF_UART3_TX, AF_TIM2_CH3, AF_SPI2_SCK, AF_SPI1_SCK, AF_I2C2_SCL, AF_COMP1_OUT, AF_INVALID, AF_INVALID } },
    {"PB11", { AF_GPIO, AF_LPUART1_TX, AF_UART3_RX, AF_TIM2_CH4, AF_SPI2_MOSI, AF_SPI1_CS, AF_I2C2_SDA, AF_COMP2_OUT, AF_INVALID, AF_INVALID } },
    {"PB12", { AF_GPIO, AF_INVALID, AF_INVALID, AF_TIM1_BKIN, AF_SPI2_CS, AF_TIM15_BKIN, AF_INVALID, AF_CAN2_RX, AF_INVALID, AF_INVALID } },
    {"PB13", { AF_GPIO, AF_UART3_CTS, AF_INVALID, AF_TIM1_CH1N, AF_SPI2_SCK, AF_TIM15_CH1N, AF_I2C2_SCL, AF_CAN2_TX, AF_INVALID, AF_INVALID } },
    {"PB14", { AF_GPIO, AF_UART3_RTS, AF_MCO2, AF_TIM1_CH2N, AF_SPI2_MISO, AF_TIM15_CH1, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PB15", { AF_GPIO, AF_INVALID, AF_TIM15_CH1N, AF_TIM1_CH3N, AF_SPI2_MOSI, AF_TIM15_CH2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
#endif
#ifdef BSP_USING_GPIO2
    { "PC0", { AF_GPIO, AF_LPUART1_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_CH1, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PC1", { AF_GPIO, AF_LPUART1_TX, AF_TIM15_CH1, AF_INVALID, AF_INVALID, AF_TIM1_CH2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PC2", { AF_GPIO, AF_SPI2_MISO, AF_TIM15_CH2, AF_INVALID, AF_INVALID, AF_TIM1_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PC3", { AF_GPIO, AF_SPI2_MOSI, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM1_CH4, AF_INVALID, AF_SPI4_CS, AF_INVALID, AF_INVALID } },
    { "PC4", { AF_GPIO, AF_UART1_TX, AF_INVALID, AF_TIM2_CH1_ETR, AF_UART3_TX, AF_TIM1_ETR, AF_I2C2_SCL, AF_SPI4_MISO, AF_INVALID, AF_INVALID } },
    { "PC5", { AF_GPIO, AF_UART1_RX, AF_INVALID, AF_TIM2_CH2, AF_UART3_RX, AF_TIM15_BKIN, AF_INVALID, AF_SPI4_MOSI, AF_INVALID, AF_INVALID } },
    { "PC6", { AF_GPIO, AF_TIM3_CH1, AF_SPI2_IO3, AF_TIM2_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI4_IO3, AF_INVALID, AF_INVALID } },
    { "PC7", { AF_GPIO, AF_TIM3_CH2, AF_SPI2_IO2, AF_TIM2_CH4, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI4_IO2, AF_INVALID, AF_INVALID } },
    { "PC8", { AF_GPIO, AF_TIM3_CH3, AF_TIM1_CH1, AF_SPI3_IO3, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI4_SCK, AF_INVALID, AF_INVALID } },
    { "PC9", { AF_GPIO, AF_TIM3_CH4, AF_TIM1_CH2, AF_SPI3_IO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC10", { AF_GPIO, AF_INVALID, AF_TIM1_CH3, AF_SPI3_SCK, AF_UART3_TX, AF_UART4_TX, AF_INVALID, AF_SPI3_IO3, AF_INVALID, AF_INVALID } },
    {"PC11", { AF_GPIO, AF_INVALID, AF_TIM1_CH4, AF_SPI3_MISO, AF_UART3_RX, AF_UART4_RX, AF_INVALID, AF_SPI3_SCK, AF_INVALID, AF_INVALID } },
    {"PC12", { AF_GPIO, AF_INVALID, AF_TIM14_CH1, AF_SPI3_MOSI, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC13", { AF_GPIO, AF_INVALID, AF_TIM1_BKIN, AF_INVALID, AF_INVALID, AF_TIM1_CH1N, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC14", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PC15", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD0", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_CAN1_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD1", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_CAN1_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD2", { AF_GPIO, AF_MCO2, AF_TIM3_ETR, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD3", { AF_GPIO, AF_INVALID, AF_TIM2_CH1_ETR, AF_INVALID, AF_UART2_CTS, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD4", { AF_GPIO, AF_RSTO, AF_TIM2_CH2, AF_INVALID, AF_UART2_RTS, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD5", { AF_GPIO, AF_REMAP, AF_INVALID, AF_INVALID, AF_UART2_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD6", { AF_GPIO, AF_INVALID, AF_TIM2_CH4, AF_INVALID, AF_UART2_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD7", { AF_GPIO, AF_INVALID, AF_TIM2_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD8", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_UART3_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PD9", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_UART3_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PD10", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PD11", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_UART3_CTS, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PD12", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_UART3_RTS, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM4_CH1 } },
    {"PD13", { AF_GPIO, AF_INVALID, AF_INVALID, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_SPI3_CS, AF_SPI3_IO2, AF_INVALID, AF_TIM4_CH2 } },
    {"PD14", { AF_GPIO, AF_INVALID, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_SPI3_MISO, AF_INVALID, AF_INVALID, AF_TIM4_CH3 } },
    {"PD15", { AF_GPIO, AF_SPI2_CS, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI3_IO2, AF_SPI3_CS, AF_INVALID, AF_TIM4_CH4 } },
#endif
    { "PE0", { AF_GPIO, AF_INVALID, AF_INVALID, AF_TIM16_CH1, AF_UART1_TX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_TIM4_ETR } },
    { "PE1", { AF_GPIO, AF_INVALID, AF_INVALID, AF_TIM17_CH1, AF_UART1_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE2", { AF_GPIO, AF_INVALID, AF_TIM3_CH1, AF_INVALID, AF_UART1_CTS, AF_INVALID, AF_SPI3_MOSI, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE3", { AF_GPIO, AF_INVALID, AF_TIM3_CH2, AF_INVALID, AF_UART1_RTS, AF_INVALID, AF_SPI3_SCK, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE4", { AF_GPIO, AF_INVALID, AF_TIM3_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI3_IO3, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE5", { AF_GPIO, AF_INVALID, AF_TIM3_CH4, AF_INVALID, AF_SPI3_MISO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE6", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_SPI3_MOSI, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE7", { AF_GPIO, AF_INVALID, AF_TIM1_ETR, AF_INVALID, AF_SPI3_SCK, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE8", { AF_GPIO, AF_INVALID, AF_TIM1_CH1N, AF_INVALID, AF_SPI3_CS, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PE9", { AF_GPIO, AF_INVALID, AF_TIM1_CH1, AF_INVALID, AF_SPI3_IO3, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PE10", { AF_GPIO, AF_INVALID, AF_TIM1_CH2N, AF_INVALID, AF_SPI3_IO2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PE11", { AF_GPIO, AF_INVALID, AF_TIM1_CH2, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PE12", { AF_GPIO, AF_INVALID, AF_TIM1_CH3N, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PE13", { AF_GPIO, AF_INVALID, AF_TIM1_CH3, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PE14", { AF_GPIO, AF_INVALID, AF_TIM1_CH4, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    {"PE15", { AF_GPIO, AF_INVALID, AF_TIM1_BKIN, AF_INVALID, AF_UART3_RX, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF0", { AF_GPIO, AF_TIM14_CH1, AF_INVALID, AF_INVALID, AF_SPI2_CS, AF_INVALID, AF_I2C2_SDA, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF1", { AF_GPIO, AF_TIM15_CH1N, AF_INVALID, AF_INVALID, AF_SPI2_SCK, AF_INVALID, AF_I2C2_SCL, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF2", { AF_GPIO, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
    { "PF3", { AF_GPIO, AF_BOOT, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID, AF_INVALID } },
};
#endif

#define PIN_COUNT   (sizeof(gpio_table)/sizeof(gpio_table[0]))

static uint8_t pin_used[PIN_COUNT] = {0};

static const enum_GPIOx_t  port_tbl[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF};
static const uint16_t      pin_tbl[] = {GPIO_PIN_0,GPIO_PIN_1,GPIO_PIN_2,GPIO_PIN_3,GPIO_PIN_4,GPIO_PIN_5,GPIO_PIN_6,GPIO_PIN_7,GPIO_PIN_8,GPIO_PIN_9,GPIO_PIN_10,GPIO_PIN_11,GPIO_PIN_12,GPIO_PIN_13,GPIO_PIN_14,GPIO_PIN_15};

bool drv_pin_init(char* name, pin_func_t func, uint32_t mode, uint32_t pull)
{
    size_t i = 0, j = 0;
    GPIO_InitTypeDef GPIO_Handle;
    int pinIdx = atoi(&name[2]);

    if(pinIdx > 15)
    {
        return false;
    }

    GPIO_Handle.Mode      = mode;
    GPIO_Handle.Pull      = pull;
    for(i = 0; i < PIN_COUNT; i++)
    {
        if (0 == strcmp(name, gpio_table[i].name))
        {
            /* gpio has be initialized for func's function */
            if(pin_used[i] == func)
            {
                return true;
            }

            /* gpio has be initialized for other function */
            if(pin_used[i] != AF_INVALID)
            {
                return false;
            }

            /* find out func's function alternate value */
            for(j = 0; j < PIN_FUNC_MAX_SIZE; j++)
            {
                if(func == gpio_table[i].func[j])
                {
                    GPIO_Handle.Alternate = j;
                    break;
                }
            }
            if(j == PIN_FUNC_MAX_SIZE)
            {
                return false;
            }
            break;
        }
    }

    /* cannot find gpio by name */
    if(i == PIN_COUNT)
    {
        return false;
    }

    GPIO_Handle.Pin       = pin_tbl[pinIdx];
    HAL_GPIO_Init(port_tbl[name[1] - 'A'], &GPIO_Handle);
    pin_used[i] = func;
    return true;
}

bool drv_pin_init_for_function(pin_func_t func, uint32_t mode, uint32_t pull)
{
    size_t i = 0, j = 0;
    GPIO_InitTypeDef GPIO_Handle;

    GPIO_Handle.Mode      = mode;
    GPIO_Handle.Pull      = pull;

    for(i = 0; i < PIN_COUNT; i++)
    {
        /* find out func's function alternate value */
        for(j = 0; j < PIN_FUNC_MAX_SIZE; j++)
        {
            if((func == gpio_table[i].func[j]) && (pin_used[i] != AF_INVALID))
            {
                GPIO_Handle.Alternate = j;
                break;
            }
        }
        if(j != PIN_FUNC_MAX_SIZE)
        {
            break;
        }
    }

    /* cannot find gpio by name */
    if(i == PIN_COUNT)
    {
        return false;
    }

    GPIO_Handle.Pin       = pin_tbl[atoi(&gpio_table[i].name[2])];
    HAL_GPIO_Init(port_tbl[gpio_table[i].name[1] - 'A'], &GPIO_Handle);
    pin_used[i] = func;

    return true;
}

